<?php
namespace App\Http\Controllers\Api;

use App\Requests\CodeLoginRequest;
use App\Requests\LoginRequest;
use App\Requests\WXLoginRequest;
use App\Services\LoginService;
use Carbon\Carbon;
use Framework\BaseController;
use Framework\Hope;



class LoginController extends BaseController
{


    /** 登录
     * @param LoginRequest $request
     * @param LoginService $LoginService
     * @return mixed
     */
    public function login(LoginRequest $request, LoginService $LoginService)
    {

        $phone = $request->phone();
        $password = $request->password();
        $client_id = $request->input('cid', '');
        if(!$client_id){
            $client_id = '';
        }
        $info = $LoginService->login($phone, $password, $client_id);
        $this->retSuccess($info);
    }

    /** 短信验证码登录
     * @param CodeLoginRequest $request
     * @param LoginService $LoginService
     */
    public function codeLogin(CodeLoginRequest $request, LoginService $LoginService)
    {
        $phone = $request->phone();
        $code = $request->code();
        $client_id = $request->input('cid', '');
        if(!$client_id){
            $client_id = '';
        }
        $info = $LoginService->codeLogin($phone, $code, $client_id);
        $this->retSuccess($info);
    }

    /** 微信授权登录
     * @param WXLoginRequest $request
     * @param LoginService $LoginService
     */
    public function wxlogin(WXLoginRequest $request,LoginService $LoginService)
    {
        $code = $request->code();
        $res = $LoginService->wx_login($code);
        return $this->retSuccess($res);
    }



}
